package com.up.demo;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.up.widgets.ExAdapter;
import com.up.widgets.SeparatedListAdapter;

public class MainActivity extends Activity {
    
	
	private SeparatedListAdapter sAdapter;
	
	public Map<String,?> createObject(String title, String image) {
		Map<String,String> item = new HashMap<String,String>();  
		item.put("title", title);
		item.put("image", image);
		return item;
	}
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        sAdapter = new SeparatedListAdapter(this,R.layout.demoheader);
        
        section_one.add(createObject("This is Image 1","http://reliancenetconnect.co.in/images/hotmail.jpg"));
        section_one.add(createObject("This is Image 2","http://reliancenetconnect.co.in/images/icon_youtube.jpg"));
        section_one.add(createObject("This is Image 3","http://reliancenetconnect.co.in/images/icon_Ebay.jpg"));
        section_one.add(createObject("This is Image 4","http://reliancenetconnect.co.in/images/icon_irctc.jpg"));
        
        section_two.add(createObject("Image 1 in different header","http://reliancenetconnect.co.in/images/hotmail.jpg"));
        section_two.add(createObject("Image 2 in different header","http://reliancenetconnect.co.in/images/icon_youtube.jpg"));
        section_two.add(createObject("Image 3 in different header","http://reliancenetconnect.co.in/images/icon_Ebay.jpg"));
        section_two.add(createObject("Image 4 in different header","http://reliancenetconnect.co.in/images/icon_irctc.jpg"));
        
        ExAdapter exone = new ExAdapter(this, R.layout.demorow, section_one);
		sAdapter.addSection("Section One", exone);
		
		ExAdapter extwo = new ExAdapter(this, R.layout.demorow, section_two);
		sAdapter.addSection("Section Two", extwo);
		
		ListView list = new ListView(this);
        list.setAdapter(sAdapter);
        
        list.setOnItemClickListener(new OnItemClickListener() {
       	 	@Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
       	 		Map<String,?> one = (Map<String,?>) parent.getAdapter().getItem(position);
       		 	Toast.makeText(getApplicationContext(), one.get("title").toString(), Toast.LENGTH_LONG).show();
       	 	}
       });
       
       setContentView(list);
		
    }
    
    List<Map<String,?>> section_one = new LinkedList<Map<String,?>>();
    List<Map<String,?>> section_two = new LinkedList<Map<String,?>>();
    
    
}